# 继承：总结：在定义子类时要继承父类，只需要类名后面的小括号()中写上父类的名字，那么父类的属性、方法，会被继承给子类。
class Animal:
    def eat(self):
        print("我可以吃饭")
        pass
    def sleep(self):
        print("我可以睡觉")
        pass
    pass
class Cat(Animal):
    def play(self):
        print("我喜欢玩毛线球")
    pass
bsm=Cat()
bsm.eat()
bsm.sleep()
bsm.play()
# ---------------------多继承--------------------------
class ShuiGuo:
    def sweet(self):
        print("水果是甜的")
        pass
    pass
class ShuCai:
    def youyingyang(self):
        print("蔬菜有营养")
        pass
    pass
class XiHongShi(ShuiGuo,ShuCai):
    pass
xhs=XiHongShi()
xhs.sweet()
xhs.youyingyang()
# 继承时，子类调用方法的顺序
class Base:
    def test(self):
        print("我是Base中的Test方法")
        pass
    pass
class Base1:
    def test(self):
        print("我是Base1中的Test方法")
        pass
    pass
class A(Base):
    def test(self):
        print("我是A中的Test方法,我继承的是Base")
        pass
    pass
class B(Base1):
    def test(self):
        print("我是B中的Test方法,我继承的是Base1")
        pass
    pass
class C(A,B):
    pass
c=C()
c.test()
# __mro__ 方法解析顺序:方法的执行顺序可以用mro查看。
# 案例代码查找顺序为 C->A->Base->B>Base1, 一旦找到，则寻找过程立即中断，便不会再继续找了
print(C.__mro__)


# 继承的传递:继承具有传递性
class Grandfather:
    def eat(self):
        print("吃饭")
        pass
    pass
class Father(Grandfather):
    pass
class Son(Father):
    pass
xiaoming=Son()
xiaoming.eat()


